package com.tuling.code.algorithm.loadbalance.simple;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * 随机（Random）法
 * 
 * @author javaw
 *
 */
public class Random implements LoadBlanceStragety {

	private java.util.Random random = new java.util.Random();

	@Override
	public String getServer(String src) {
		Map<String, Integer> serverMap = new HashMap<>();
		serverMap.putAll(IpMap.serverWeightMap);
		Set<String> keySet = serverMap.keySet();

		ArrayList<String> keyList = new ArrayList<String>();
		keyList.addAll(keySet);

		int randomPos = random.nextInt(keyList.size());
		return keyList.get(randomPos);
	}

}
